package axonactive.vision.traning.test.selenium.bean;

import java.util.List;

public class AutoitThread implements Runnable {

	private String scriptName;
	private List<String> parameters;

	public AutoitThread(String scriptName, List<String> params) {
		this.scriptName = scriptName;
		parameters = params;
	}

	@Override
	public void run() {
		try {
			String command = buildCommand();
			System.out.print("Execute command: " + command +"\n");
			Process p = Runtime.getRuntime().exec(command);
			p.waitFor();
			/*for(int i = 0; i < 50; i++) {
				System.out.print("execute time:" + i +"\n");
			}
			System.out.print("end");*/
		} catch (Exception e) {
			System.out.print(e.getMessage());
		}
	}

	private String buildCommand() {
		StringBuffer command = new StringBuffer(scriptName);
		if(parameters != null || parameters.size() > 0) {
			command.append(" ");
			int size = parameters.size();
			for(int i = 0; i < size; i++){
				command.append(parameters.get(i));
				command.append(" ");
			}
		}
		return command.toString().trim();
	}

	public void addParameter(String parameter) {
		this.parameters.add(parameter);
	}

	public void clearParameters() {
		this.parameters.clear();
	}

	public String getScriptName() {
		return scriptName;
	}

	public void setScriptName(String scriptName) {
		this.scriptName = scriptName;
	}

	public List<String> getParameters() {
		return parameters;
	}

	public void setParameters(List<String> parameters) {
		this.parameters = parameters;
	}

}
